#!/bin/sh
# This regression test is a part of SIPp.
# A UAS answers a request by the transaction a received request started
# (start_txn on <recv>, response_txn on <send>): its 200 to the INVITE
# after an INFO has the INVITE's headers, and the INVITE sent again after
# the INFO gets its last response, the 180, again.
. "`dirname "$0"`/../functions"; init

sippbg -sf uas.xml -i 127.0.0.1 -p 29200 -m 1 -timeout 15 -timeout_error -trace_stat \
    -stf uas.csv
uas=$pid
sippfg -sf uac.xml -i 127.0.0.1 -p 29201 -m 1 -nr 127.0.0.1:29200 \
    -timeout 10 -timeout_error >/dev/null 2>&1
status=$?
wait $uas
uas_status=$?
# The retransmissions the UAS sent: the 180, once.
retrans=`awk -F';' 'NR == 1 { for (i = 1; i <= NF; i++) if ($i == "Retransmissions(C)") c = i }
    END { print $c }' uas.csv`
rm -f uas.csv

if test $status -ne 0; then
    fail "UAC failed with $status"
elif test $uas_status -ne 0; then
    fail "UAS failed with $uas_status"
elif test "$retrans" != 1; then
    fail "the UAS sent $retrans retransmissions, not 1"
else
    ok
fi
